/**
* Copyright (C) 2018-2022
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制，未经购买不得使用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package co.yixiang.modules.tanzer.service.impl;

import co.yixiang.modules.tanzer.domain.GoodsWholesaleRecord;
import co.yixiang.common.service.impl.BaseServiceImpl;
import lombok.AllArgsConstructor;
import co.yixiang.dozer.service.IGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import co.yixiang.common.utils.QueryHelpPlus;
import co.yixiang.utils.ValidationUtil;
import co.yixiang.utils.FileUtil;
import co.yixiang.modules.tanzer.service.GoodsWholesaleRecordService;
import co.yixiang.modules.tanzer.service.dto.GoodsWholesaleRecordDto;
import co.yixiang.modules.tanzer.service.dto.GoodsWholesaleRecordQueryCriteria;
import co.yixiang.modules.tanzer.service.mapper.GoodsWholesaleRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
// 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.CacheEvict;
//import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import co.yixiang.domain.PageResult;
/**
* @author tanzer
* @date 2024-08-04
*/
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "goodsWholesaleRecord")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class GoodsWholesaleRecordServiceImpl extends BaseServiceImpl<GoodsWholesaleRecordMapper, GoodsWholesaleRecord> implements GoodsWholesaleRecordService {

    private final IGenerator generator;

    @Autowired
    private GoodsWholesaleRecordMapper goodsWholesaleRecordMapper;

    @Override
    //@Cacheable
    public PageResult<GoodsWholesaleRecord> queryAll(GoodsWholesaleRecord criteria, Pageable pageable) {
        getPage(pageable);
        PageInfo<GoodsWholesaleRecord> page = new PageInfo<>(goodsWholesaleRecordMapper.selectAllList(criteria));
        return generator.convertPageInfo(page,GoodsWholesaleRecord.class);
    }


    @Override
    //@Cacheable
    public List<GoodsWholesaleRecord> queryAll(GoodsWholesaleRecordQueryCriteria criteria){
        return baseMapper.selectList(QueryHelpPlus.getPredicate(GoodsWholesaleRecord.class, criteria));
    }


    @Override
    public void download(List<GoodsWholesaleRecordDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (GoodsWholesaleRecordDto goodsWholesaleRecord : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("产品id", goodsWholesaleRecord.getProductId());
            map.put("规格备注", goodsWholesaleRecord.getStandards());
            map.put("数量备注", goodsWholesaleRecord.getNum());
            map.put("总数量", goodsWholesaleRecord.getTotalNum());
            map.put("单价", goodsWholesaleRecord.getUnitCost());
            map.put("总费用", goodsWholesaleRecord.getTotalCost());
            map.put("购买人", goodsWholesaleRecord.getPurchaser());
            map.put("购买人电话", goodsWholesaleRecord.getPurchaserTel());
            map.put("购买人微信", goodsWholesaleRecord.getPurchaserWechat());
            map.put("购买人地址", goodsWholesaleRecord.getPurchaserAddr());
            map.put("备注说明", goodsWholesaleRecord.getRemark());
            map.put(" updateTime",  goodsWholesaleRecord.getUpdateTime());
            map.put(" isDel",  goodsWholesaleRecord.getIsDel());
            map.put(" attribute1",  goodsWholesaleRecord.getAttribute1());
            map.put(" attribute2",  goodsWholesaleRecord.getAttribute2());
            map.put(" attribute3",  goodsWholesaleRecord.getAttribute3());
            map.put(" attribute4",  goodsWholesaleRecord.getAttribute4());
            map.put(" attribute5",  goodsWholesaleRecord.getAttribute5());
            map.put("创建日期", goodsWholesaleRecord.getCreateTime());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
